import requests, json


def show_run(id, ip, port=80):
    url = 'http://{}:{}/command-api'.format(ip, str(port))
    data = {
        'jsonrpc': '2.0',
        'id': "70853aff-af77-420e-8f3c-fa9430733a19",
        'method': 'executeCmds'
    }
    data['params'] = [
        {
            "format": "text",
            "version": 1,
            "cmds": [
                "show run"
            ]
        }
    ]
    resp = requests.post(url, json.dumps(data), timeout=10)
    resp = json.loads(resp.content.decode())
    file_name = 'show-run-{}-{}.txt'.format(str(id), ip)
    print(resp['result'][0])
    with open(file_name, 'r+') as f:
        f.write(resp['result'][0]['sourceDetails'])


show_run(16, '1.1.1.1')
